import { Component, OnInit } from '@angular/core';
import { ProblemsService} from '../problems.service'
import { Http, Response, RequestOptions, Headers} from '@angular/http';

@Component({
  selector: 'app-all-problem',
  templateUrl: './all-problem.component.html',
  styleUrls: ['./all-problem.component.css']
})



export class AllProblemComponent implements OnInit {

  problems:Problem[];
  data:Object;
  loading:boolean;

  constructor(
    private problemService:ProblemsService,
    private http:Http,
  ) { }

  ngOnInit() {

    this.problems = [
      {title:'1',creator:'2',company:'3',type:'4',state:'5'},
      {title:'11',creator:'2',company:'3',type:'4',state:'5'},
      {title:'111',creator:'2',company:'3',type:'4',state:'5'},
      ];

    // this.problemService.testGet().subscribe(
    //   (res: Response) => {
    //     this.data = res.json();
    //     // console.log(this.data);
    //     console.log(this.data);
    //   });
    // this.makeHeaders();
  }

  makeRequest(): void {
    this.loading = true;
    this.http.request('http://jsonplaceholder.typicode.com/posts/1')
      .subscribe((res: Response) => {
        this.data = res.json();
        this.loading = false;
        console.log(this.data);
      });
  }

  makeHeaders(): void {
    // const headers: Headers = new Headers();
    // headers.append("Access-Control-Allow-Origin", "*");
    //
    // const opts: RequestOptions = new RequestOptions();
    // opts.headers = headers;

    this.http.get('http://localhost:8080/hello')
      .subscribe((res: Response) => {
        this.data = res.json();
      });
  }

}
export interface Problem{
  title;
  creator;
  company;
  type;
  state;
}
